<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>

<html>
	<head>
		<title>仓库档案</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$("#table").datagrid({
				title:"仓库档案",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/warehouse/listPageWareHouse',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
	                {field:'ck',checkbox:true},
				    {title:'编号',field:'id',hidden:true}
				]],
				columns:[[
					{title:'仓库编码',field:'code',width:50,align:'center'},
					{title:'仓库类型',field:'type',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(value == 0){
							return "客户库";
						}
						if(value == 1){
							return "甲供库";
						}
						if(value == 2){
							return "工余料库";
						}
						if(value == 3){
							return "订单料库";
						}
						if(value == 4){
							return "厂家库";
						}
					}},
					{title:'仓库名称',field:'name',width:100,align:'center'},
					{title:'所属部门',field:'dept_name',width:100,align:'center'},
					{title:'仓库地址',field:'address',width:150,align:'center'},
					{title:'联系方式',field:'contact',width:100,align:'center'},
					{title:'负责人',field:'admin',width:100,align:'center'},
					{title:'编辑',field:'edit',fit:true,width:50,align:'center',formatter:function(value,rowDate,rowIndex){
						return "<input type='button'  style='border:0px #ff0000 solid;width:25px;height:15px;cursor:pointer'class='icon-modify'  onClick='addOrEditWareHouse(1,\""+rowDate.id+"\")'/>";
					}}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				},
				onDblClickRow:function(rowIndex,rowData){
					addOrEditWareHouse(1,rowData.id);
				}
			});
		});
		function deleteWarehouse(){
			var rows=$('#table').datagrid('getSelections');
			var deleteVar="";
			if(rows.length==0)
			{
				$.messager.alert('提示','选中要删除的记录');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					deleteVar+=rows[i].id;
				}else
				{
					deleteVar+=rows[i].id+",";
				}
			}
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/warehouse/deleteWareHouse",
						data:"ids="+deleteVar,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function addOrEditWareHouse(type,id){
			if(type==0){
				openDialogResize("<%=contextPath %>/springViews/warehouse/addOrEditWareHouse.jsp?callback=rtCallBack",1000, 800);
			}else{
				openDialogResize('<%=contextPath %>/springViews/warehouse/addOrEditWareHouse.jsp?callback=rtCallBack&id='+id,1000, 800);
			}
		}
		function doSearch() {
			var dept_id = $("#dept_id").combotree('getValue');
			$('#table').datagrid('load', {
				dept_id : dept_id
			});
		}
	</script>
	<body style="height:97%">
		<div id="table" data-options="fit:true"></div>
	<div id="tb" style="padding:3px;height:auto">
		<div style="float:left;">
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteWarehouse();">删除</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditWareHouse(0)">新增</a>
		</div>
		<div align="right">
		所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp; 
		</div>
		</div>
	</body>
</html>
